<?php //echo "<pre>"; die(print_r($data));?>
<div class="breadcrumbwidget">
	<ul class="skins">
        <li><a href="default" class="skin-color default"></a></li>
        <li><a href="orange" class="skin-color orange"></a></li>
        <li>&nbsp;</li>
        <li class="fixed"><a href="" class="skin-layout fixed"></a></li>
        <li class="wide"><a href="" class="skin-layout wide"></a></li>
    </ul><!--skins-->
	<ul class="breadcrumb">
        <li><a href="<?php echo $baseurl?>">Trang chủ</a> <span class="divider">/</span></li>
        <li class="active">Báo cáo</li>
    </ul>
</div><!--breadcrumbwidget-->
<div class="pagetitle">
	<h1>Báo cáo sử dụng E-coupon</h1> <span></span>
</div>
<div class="maincontent">
    <div class="contentinner">    
    
        <div id="dyntable_length" class="dataTables_length  content-dashboard">
            <button id="report" class="btn btn-success" type="button">Xuất báo cáo</button>
        </div>
    	<table class="table table-bordered">
            <colgroup>
                <col class="con0" />
                <col class="con1" />
                <col class="con0" />
                <col class="con1" />
                <col class="con0" />
            </colgroup>
            <thead>
                <tr style="background-color: rgba(0,0,0,.1);">
                    <td colspan="6" style="text-align: center;font-size: 18px;"><?php echo 'Tên E-coupon: '.$info->title;?></td>
                </tr>
                <tr style="background-color: rgba(0,0,0,.2);">
                    <td colspan="6" style="text-align: right;">Số lượng coupon: <?php echo $info->amount;?></td>
                </tr>
                <tr style="background-color: rgba(0,0,0,.2);">
                    <td colspan="6" style="text-align: right;">Đã nhận: <?php echo $info->amount_available;?></td>
                </tr>
                <tr style="background-color: rgba(0,0,0,.2);">
                    <td colspan="6" style="text-align: right;">Đã sử dụng: <?php echo $info->used;?></td>
                </tr>                
                <tr style="background-color: rgba(0,0,0,.2);">
                    <td colspan="6" style="text-align: right;">Còn lại: <?php echo $info->amount - $info->amount_available;?></td>
                </tr>
                    
                <tr>
                    <th style="width: 8%;">STT</th>
                    <th>Mã E-coupon</th>
					<th>Trạng thái</th>
                    <th>User</th>
                    <th>Ngày nhận</th>
                    <th>Ngày sử dụng</th>
                </tr>
            </thead>
            <tbody>
            <?php $i=1; if(!in_array($data, array(null, '', '0'))):?>
            <?php foreach($data AS $el=>$le):?>
                <tr>
                    <td><?php echo $per_page * $pageg + $i;?></td>
                    <td><?php echo $le->code_coupon?></td> 
					<td>
                    <?php if($le->active == 0):?>
                        <span>E-coupon chưa phát</span>
                    <?php elseif($le->active == 1):?>
                        <span>E-coupon đã được nhận</span>
                    <?php elseif($le->active == 2):?>
                        <span>E-coupon đã sử dụng</span>
                    <?php endif;?>
                    </td>
					<td><?php echo $le->username ? $le->username : "Đang cập nhật";?></td>
                    <td><?php echo $le->created ? date('d-m-Y', strtotime($le->created)) : "Đang cập nhật";?></td>
                    <td><?php echo $le->time_use ? date('d-m-Y', strtotime($le->time_use)) : "Đang cập nhật";?></td>
                </tr>
            <?php $i++; endforeach;?>
            <?php endif?>
            </tbody>
        </table>
        <div class="dataTables_info" id="dyntable_info">
            <div class="pagination">
                <?php echo $this->pagination->create_links();?> 
            </div>
        </div>
    </div>
</div>

<div id="hideReport" style="display: none;"></div>
<style>
.table th, .table td {
vertical-align: middle !important;
}
</style>

<script type="text/javascript">
    $(document).ready(function(){
        $('#report').on('click', function(){
            $.ajax({
               type: "GET",
               url: baseUrl+'manage/ecoupon/report/<?php echo $ids;?>',
               beforeSend: function(){
                    showPreload();
               },
               success: function(n){
                    $('#hideReport').html(n);
                    exportToExcel();
               }  
            });
        });
    });
</script>